#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTextEdit>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //标题
    this->setWindowTitle("MongoDB客户端");
    //ICO小图标
    this->setWindowIcon(QIcon(":/new/prefix1/ico"));



    //顶部菜单按钮布局
    topLayout = new QHBoxLayout(this);
    topLayout->setGeometry(QRect(0,0,this->geometry().width(),75));

    //连接按钮
    connBtn = new QToolButton(this);
    connBtn->setIcon(QIcon(":/new/prefix1/conn"));
    connBtn->setText("连接");
    connBtn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    connBtn->setFocusPolicy(Qt::NoFocus);
    connBtn->setGeometry(QRect(0,0,75,75));
    connBtn->setStyleSheet("QToolButton{border:0px;padding-top:20px}QToolButton:hover{background-color:#C0DCF3;border-radius:4px;}");

    selectBtn = new QToolButton(this);
    selectBtn->setIcon(QIcon(":/new/prefix1/conn"));
    selectBtn->setText("新建查询");
    selectBtn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    selectBtn->setFocusPolicy(Qt::NoFocus);
    selectBtn->setGeometry(QRect(75,0,75,75));
    selectBtn->setStyleSheet("QToolButton{border:0px;padding-top:20px}QToolButton:hover{background-color:#C0DCF3;border-radius:4px;}");
    topLayout->addWidget(connBtn);
    topLayout->addWidget(selectBtn);

    splitter = new QSplitter(this);
    splitter->setGeometry(QRect(0,75,this->geometry().width(),this->geometry().height()-75));
    treeView = new QTreeView(splitter);
    treeView->setGeometry(QRect(0,75,150,200));
    splitter->addWidget(treeView);
    splitter->setStretchFactor(0,1);

    QTextEdit *str1 = new QTextEdit(splitter);
    str1->setPlaceholderText("test1");
    splitter->addWidget(str1);
    splitter->setStretchFactor(1,3);

    qDebug() << "宽度"  ;
}

void MainWindow::changeEvent(QEvent *event)
{
    if(QEvent::WindowStateChange == event->type())
    {
        if(this->windowState()==Qt::WindowMaximized){
            //qDebug()<<"old state ="<< "放大" << this->width();
        }else if(this->windowState()==Qt::WindowNoState){
            //qDebug()<<"old state ="<< "正常" << this->width();
        }
    }
}

void MainWindow::resizeEvent(QResizeEvent * re)
{
    qDebug()<<"old state ="<< "其它" << this->width();
    splitter->setGeometry(QRect(0,75,this->geometry().width(),this->geometry().height()-75));
}

MainWindow::~MainWindow()
{
    delete ui;
}

